package net.capstone.cra.smartcontroller;

import net.capstone.cra.smartcontroller.util.ByteConverter;

/**
 * The Class SignalDecoder.
 */
public class SignalDecoder {
	
	/** The Constant TYPE_VIB. */
	private static final byte TYPE_VIB = 0x1;
	
	/** The Constant TYPE_CTRLNUM. */
	private static final byte TYPE_CTRLNUM = 0x2;
	
	/**
	 * Decode.
	 *
	 * @param sig the sig
	 * @return the signal
	 */
	public static Signal decode(byte[] sig) {
		if((sig[0] & TYPE_VIB) == TYPE_VIB)
		{
			int milliSec = ByteConverter.byte2int(sig, 1);
			return new Signal(Signal.SIG_VIBRATION, milliSec);  
		}
		if((sig[0] & TYPE_CTRLNUM) == TYPE_CTRLNUM) {
			int CtrlNo = ByteConverter.byte2int(sig, 1);
			return new Signal(Signal.SIG_CONTROLLERNUM, CtrlNo);
		}
		return null;
	}
}